package com.manager.enterprise.module.controller;

import com.manager.commons.annotation.Module;
import com.manager.commons.annotation.Operation;
import com.manager.commons.base.DataGrid;
import com.manager.core.web.json.AjaxJson;
import com.manager.enterprise.module.entity.GenUser;
import com.manager.enterprise.module.service.GenUserService;
import com.manager.enterprise.web.controller.AdminController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * GenUserController
 *用户表 
 * @author manager
 * @version 1.0
 */
@Controller()
@Module(parent = "account-manager", title = "用户表",code="/gen/user")
public class GenUserController extends AdminController<GenUser> {
    private final String baseUrl = "/gen/user";
    @Autowired
    private GenUserService _service;

    /**
     * 列表
     *
     * @return
     */
    @RequestMapping(baseUrl+"/index")
    public ModelAndView index() {
        return getModelAndView("/gen/user-index");
    }

    /**
     * 新增
     *
     * @return
     */
    @GetMapping(baseUrl+"/add")
    public ModelAndView add() {
        return getModelAndView("/gen/user-edit", getModel());
    }

    /**
     * 新增
     *
     * @return
     */
    @RequestMapping(baseUrl+"/edit")
    public ModelAndView edit() {
        return getModelAndView( "/gen/user-edit", _service.findMap(getParams()));
    }

    /**
     * 删除数据
     *
     * @return
     */
    @RequestMapping(value = baseUrl+"/delete", method = RequestMethod.POST)
    public @ResponseBody AjaxJson delete() {
        return _service.delete(getParams());
    }



    /**
     * 分页
     *
     * @return
     */
    @RequestMapping(value =baseUrl+ "/list")
    @Operation(title = "列表")
    public @ResponseBody DataGrid page() {
        return _service.queryPage(getParams());
    }

    /**
     * 保存
     *
     * @returna
     */
    @PostMapping(value = baseUrl+"/save")
    public @ResponseBody AjaxJson save() {
        try {
            return _service.mySave(getParams());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(), e);
        }
        return new AjaxJson("异常错误，请稍后再试");
    }

    /**
     * 改变数据状态
     *
     * @return
     */
    @PostMapping(value =baseUrl+ "/status")
    public @ResponseBody AjaxJson status() {
        return _service.status(getParams());
    }

    /**
     * 改变数据状态
     *
     * @return
     */
    @PostMapping(value = baseUrl + "/reset")
    public @ResponseBody AjaxJson reset() {
        return _service.reset(getParams());
    }

    @Override
    public GenUser getModel() {
        return new GenUser();
    }

}
